package com.ruoyi.performance.controller;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.performance.domain.PerfGroup;
import com.ruoyi.performance.service.PerfGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.List;

@RestController //绩效权限组
@RequestMapping("perfgroup")
public class PerfGroupController extends BaseController{
    @Resource
    PerfGroupService perfGroupService;

    @RequestMapping("get/{id}")
    public R list(@PathVariable Long id){
        return jacResult(perfGroupService.selectPerfGroupById(id));
    }

    @GetMapping("getc/{Companycode}")
    public R list(@PathVariable("Companycode") String Companycode){
        startPage();
        return result(perfGroupService.selectPerfGroupByCompanycode(Companycode));
    }

    @GetMapping("get/list")
    public R list( PerfGroup perfGroup){
        startPage();
        return result(perfGroupService.selectPerfGroupList(perfGroup));
    }

//    @GetMapping("list")
//    public R list(PerfGroup perfGroup) {
//        startPage();
//        return result(perfGroupService.selectPerfGroupList(perfGroup));
//    }


    @RequestMapping("getg")
    public R list(@PathVariable("companycode") String companycode,@PathVariable("groupcode") String groupcode,@PathVariable("groupname") String groupname){
        return result(perfGroupService.selectPerfGroupByCompanycodeAndGroupcodeAndGroupname(companycode, groupcode, groupname));
    }

    @RequestMapping("getcg/{companygroup}")
    public R list(@PathVariable("companycode") String companycode,@PathVariable("groupcode") String groupcode){
        return jacResult(perfGroupService.selectPerfGroupByCompanycodeAndGroupcode(companycode, groupcode));
    }

//    @GetMapping("get/{groupcode}")
//    public R list(@PathVariable String groupcode){
//        return jacResult(perfGroupService.selectByGroupcode(groupcode));
//    }

//    @GetMapping("get/{groupname}")
//    public R list(@PathVariable String groupname){
//        return jacResult(perfGroupService.selectByGroupname(groupname));
//    }

    @PostMapping("save")
    public R addSave(@RequestBody PerfGroup perfGroup){
        return toAjax(perfGroupService.insertPerfGroup(perfGroup));
    }

    @PostMapping("update")
    public R editSave(@RequestBody PerfGroup perfGroup){
        return toAjax(perfGroupService.updatePerfGroup(perfGroup));
    }

    @PostMapping("remove")
    public R remove(String id){
        return toAjax(perfGroupService.deletePerfGroupById(id));
    }

//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public String deletePerfGroupById(int id){
//        String result = "1";
//        List<String> checkstatus = new ArrayList<String>();
//        String ids = id.split(",");
//        for (String perfgroupId : id) {
//            Long perfgroupIdL = Long.valueOf(perfgroupId);
//            result = checkstatus(perfgroupIdL,"Delete",p)
//        }
//    }

}
